let $api = require('../../config');
Page({
    data:{
      searchList:[]
    },
	search(e){
		var val = e.detail.value;
		this.getResult(val);
	},
	/*获取结果*/
	getResult(val){
		let token = wx.getStorageSync('userInfo').token;
        let self = this;
         wx.showLoading({
            title: '搜索中',
         })
        wx.request({
            url:$api.api.search, 
            method:'GET',
            data: {
                token,
                key:val
            },
            header: {
                'content-type': 'application/json' 
            },
            success: function(res) {
                let data = res.data;
                let searchList = data.data;
                self.setData({
                    searchList
                })
                wx.hideLoading();
            }
        })
	},
     /*
    * 查询次数
    */
    getSurplusSearch(cb){
        let token = wx.getStorageSync('userInfo').token;
        let self = this;
        wx.request({
            url:$api.api.surplusSearch, 
            method:'GET',
            data: {
                token
            },
            header: {
                'content-type': 'application/json' 
            },
            success: function(res) {
                let surplusTotal = res.data.data.left_query_times;
                self.setData({ 
					surplusSearch:surplusTotal
				})
                cb && cb(surplusTotal)
            }
        })
    },
    toDetails(e){
        let code = e.currentTarget.dataset.code;
        wx.navigateTo({
            url:`../details/details?code=${code}&from=search`
        })
    }
})